package com.bingo.mpa.util;

import java.util.Calendar;
import java.util.GregorianCalendar;

import com.bingo.mpa.vo.DateMeta;

public class Common
{
	public static DateMeta getMetaDate(String dateType)
	{
		DateMeta meta = new DateMeta();
		if (dateType != null)
		{
			Calendar now = Calendar.getInstance();
			now.set(Calendar.HOUR_OF_DAY, 0);
			now.set(Calendar.MINUTE, 0);
			now.set(Calendar.SECOND, 0);
			now.add(Calendar.DAY_OF_MONTH, 1);
			meta.setEt(org.apache.commons.lang.time.DateFormatUtils.format(now, "yyyy-MM-dd"));
			now.add(Calendar.DAY_OF_MONTH, -1);
			if (dateType.startsWith("today"))// 今天
			{
				meta.setSt(org.apache.commons.lang.time.DateFormatUtils.format(now, "yyyy-MM-dd"));
			}
			else if (dateType.startsWith("yestday"))// 昨天
			{
				meta.setEt(org.apache.commons.lang.time.DateFormatUtils.format(now, "yyyy-MM-dd"));
				now.add(Calendar.DAY_OF_MONTH, -1);
				meta.setSt(org.apache.commons.lang.time.DateFormatUtils.format(now, "yyyy-MM-dd"));
			}
			else if (dateType.startsWith("week"))// 本周
			{
				int minus = new GregorianCalendar().get(GregorianCalendar.DAY_OF_WEEK) - 2;
				if (minus < 0)// 本周还没有开始
				{
					now.add(Calendar.DAY_OF_WEEK, -7);
				}
				else
				{
					now.set(Calendar.DAY_OF_WEEK, 2);// 星期一
				}
				meta.setSt(org.apache.commons.lang.time.DateFormatUtils.format(now, "yyyy-MM-dd"));
			}
			else if (dateType.startsWith("oneWeek"))// 近一周
			{
				now.add(Calendar.DAY_OF_YEAR, -7);
				meta.setSt(org.apache.commons.lang.time.DateFormatUtils.format(now, "yyyy-MM-dd"));
			}
			else if (dateType.startsWith("month"))// 本月
			{
				now.set(Calendar.DAY_OF_MONTH, 1);
				meta.setSt(org.apache.commons.lang.time.DateFormatUtils.format(now, "yyyy-MM-dd"));
			}
			else if (dateType.startsWith("oneMonth"))// 近一月
			{
				now.add(Calendar.MONTH, -1);
				meta.setSt(org.apache.commons.lang.time.DateFormatUtils.format(now, "yyyy-MM-dd"));
			}
			else if (dateType.startsWith("period"))// 近一月
			{
				meta.setSt("");
				meta.setEt("");
			}
		}
		return meta;
	}
}
